class RedPacketActivity {
    name: string;
    amount: number;
    currentParticipants: number;
    startTime: Date;

    constructor(name: string, amount: number, currentParticipants: number, startTime: Date) {
        this.name = name;
        this.amount = amount;
        this.currentParticipants = currentParticipants;
        this.startTime = startTime;
    }
}

class RedPacketScheduler {
    activities: RedPacketActivity[];

    constructor() {
        this.activities = [];
    }

    addActivity(activity: RedPacketActivity): void {
        this.activities.push(activity);
    }

    scheduleParticipants(participantCount: number): void {
        const sortedActivities = [...this.activities].sort(
            (a, b) => b.amount / b.currentParticipants - a.amount / a.currentParticipants
        );

        for (let i = 0; i < sortedActivities.length && participantCount > 0; i++) {
            const activity = sortedActivities[i];
            const remainingParticipants = participantCount >= activity.currentParticipants
                ? activity.currentParticipants
                : participantCount;

            participantCount -= remainingParticipants;
            activity.currentParticipants -= remainingParticipants;

            console.log(`${remainingParticipants}人参与${activity.name}，每人抢到金额：${activity.amount / remainingParticipants}`);
        }

        if (participantCount > 0) {
            console.log(`还有${participantCount}人无法参与任何活动`);
        }
    }
}

// 示例用法
const scheduler = new RedPacketScheduler();

// 添加红包活动
scheduler.addActivity(new RedPacketActivity("活动1", 10000, 50, new Date()));
scheduler.addActivity(new RedPacketActivity("活动2", 5000, 20, new Date()));
scheduler.addActivity(new RedPacketActivity("活动3", 20000, 100, new Date()));

// 调度参与者抢红包
scheduler.scheduleParticipants(100);